import * as types from '../types'
import {sendInfoData, getBankBranch} from '@/api'
import {Tools} from "../../lib/tools";
import router from '@/router'


const state = {
    popupVisible: false,
    nextBtnDisabled: true,
    ChooseName: "",
    OppName: "",
    placeholder: "请输入账户名称",
    inputValue: '',
    BankValue: '',
    branchListCode: "",
    BankAccountBank: [
        // {name: 'BankAccountBank', content: '账户开户行', all: '请选择账户开户行(必填)', choose: ''},
        {name: 'BankBranch', content: '账户开户行', all: '请选择账户开户行支行(必填)', choose: ''},
    ],
    tipsData: ["所有认证账户必须为借记账户，该账户将作为银联商务向开户方资金入账的结算账户。",
        "请仔细核实账户信息。", "开户行以及开户支行将在您输入结算银行账户后系统自动识别检测"],
    slotData: [
        {
            flex: 1,
            values: [],
            className: 'slot1',
            textAlign: 'center',
        },
    ],
    infoData: '',
}

const getters = {}

const actions = {
    [types.SEND_INFO_DATA]({state, rootState}) {
        state.infoData=""
        if (rootState.auxiliary.eightAuxiliarySize != "") {
            state.infoData += rootState.auxiliary.eightAuxiliaryPath
        }
        if (rootState.auxiliary.thirteenAuxiliarySize != "") {
            state.infoData += rootState.auxiliary.thirteenAuxiliaryPath
        }
        if (rootState.auxiliary.fourteenAuxiliarySize != "") {
            state.infoData += rootState.auxiliary.fourteenAuxiliaryPath
        }

        var param = {
            'service': 'dateUpload',
            'wxRequestDate': (new Date()).format("yyyyMMddhhmmss"),
            'legal_name': rootState.Authentication.LegalPersonNameData,
            'legal_idcard_no': rootState.Authentication.IDNumberData,
            'legal_mobile': rootState.Authentication.phoneNumberData,
            'legal_email': rootState.Authentication.emailData,
            'shop_name': rootState.shopPhoto.inputValue,
            'bank_no': state.branchListCode,
            'bank_branch_name': state.BankAccountBank[0].choose,
            'bank_acct_no': state.BankValue,
            'bank_acct_name': state.inputValue,
            //'shop_country_id': state.shopCountryId,
            'shop_country_id': rootState.companyAddress.areaCode,
            'shop_road': rootState.companyAddress.companyAddress[0].choose,
            'shop_house_no': rootState.companyAddress.shopHouseValue,
            'pic_list':
                '身份证正面' + ',' + '0001' + ',' + rootState.LegalPersonPhoto.SelfPortraitIDCardPath + ',' + rootState.LegalPersonPhoto.SelfPortraitIDCardSize + '' +
                '|' + '身份证返回' + ',' + '0011' + ',' + rootState.LegalPersonPhoto.nationalEmblemIDCardPath + ',' + rootState.LegalPersonPhoto.nationalEmblemIDCardSize + '' +
                '|' + '自拍照' + ',' + '0007' + ',' + rootState.LegalPersonPhoto.IdentityWitnessIDCardPath + ',' + rootState.LegalPersonPhoto.IdentityWitnessIDCardSize + '' +
                '|' + '门头照片' + ',' + '0005' + ',' + rootState.shopPhoto.doorHeadPhotoPath + ',' + rootState.shopPhoto.doorHeadPhotoSize + '' +
                '|' + '室内照片' + ',' + '0015' + ',' + rootState.shopPhoto.indoorPhotosPath + ',' + rootState.shopPhoto.indoorPhotosSize + '' +
                state.infoData
        };
        sendInfoData({
            json: param
        }).then(
            data => {
                if (data.responseCode=='0000'){
                    router.push('goSign')
                }
            }
        )
    }
}

const mutations = {
    [types.MERCHANTACCOUNT_SHOW_SELECT_LIST]() {
        router.push('searchBranch')
    },
    [types.MERCHANTACCOUNT_GET_INPUT_VALUE](state, value) {
        state.inputValue = value
    },
    [types.MERCHANTACCOUNT_GET_BANK_CHANGE](state, value) {
        state.BankValue = value
    },
    [types.MERCHANTACCOUNT_NEXT_BUTTON_CHECK](state) {
        if (
            Tools.check.isEmpty(state.inputValue) ||
            Tools.check.isEmpty(state.BankValue) ||
            Tools.check.isEmpty(state.BankAccountBank[0].choose)
        ) {
            state.nextBtnDisabled = true
        } else state.nextBtnDisabled = false
    }
}

export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getters
}